package com.heima.controller;

import com.heima.pojo.dto.UserDto;
import com.heima.pojo.vo.UserVo;
import com.heima.service.UserService;
import com.heima.utils.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 赵超
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/user-service/user")
public class UserController {

    private final UserService userService;

    @GetMapping("/search")
    public PageResult<UserVo> search(Integer pageIndex, Integer pageSize, String userName) {

        return userService.search(pageIndex, pageSize, userName);
    }

    @PostMapping
    public boolean save(@RequestBody UserDto dto) {
        return userService.save(dto) > 0;
    }

    @PutMapping("/{userId}")
    public boolean update(@PathVariable String userId, @RequestBody UserDto dto) {

        return userService.update(userId, dto) > 0;
    }

    @DeleteMapping("/{userId}")
    public boolean delete(@PathVariable String userId) {
        return userService.removeById(userId) > 0;
    }
}
